﻿using System;
using System.Collections;
using System.Threading;

namespace RMS
{
    public static class Logger
    {
        public const int ERROR = 1;
        public const int WAINING = 2;
        public const int INFO = 3;
        public const int TIP = 4;
        public const int OTHER = 5;

        private static Queue queueLog = new Queue();
        private static DateTime preTime = DateTime.Now;

        public static void Add(string strOperName, string strMsg, int logType)
        {
            queueLog.Enqueue(new Log(strOperName, getTypeByInt(logType, 0), strMsg, DateTime.Now));
        }

        /*
         * Get log type and return a string by difficult language.
         * @param {int} longType The five type define in this class
         * @param {int} lang The index of language, now support english(1) and chinese(0)
         */
        private static string getTypeByInt(int logType, int lang)
        {
            switch (logType)
            {
                case Logger.ERROR :
                    return (lang == 0) ? "错误" : "ERROR";
                case Logger.WAINING :
                    return (lang == 0) ? "警告" : "WAINING";
                case Logger.INFO :
                    return (lang == 0) ? "消息" : "INFORMATION";
                case Logger.TIP :
                    return (lang == 0) ? "建议" : "TIP";
                case Logger.OTHER:
                default:
                    return (lang == 0) ? "其它" : "OTHER";
            }
        }

        private static void sendToServer()
        {
            while (true)
            {
                Console.WriteLine("Save log data to server.");

                Thread.Sleep(300000);  // Every 5 minute to save log into server.
            }
        }
    }
}
